<template>
  <div>
    <t-dialog
      header="导入知识点"
      body="水平居中显示的对话框"
      :visible="isshow"
      @close="onReset"
      type="reset"
      :footer="false"
      width="800px"
    >
      <dk-divider style="margin: 10px 0"></dk-divider>
      <t-form
        ref="form"
        :rules="FORM_RULES"
        :data="formData"
        :colon="true"
        reset-type="initial"
        @reset="onReset"
        @submit="onSubmit"
        scrollToFirstError="smooth"
        label-width="140px"
      >
        <t-form-item label="选择文件" name="knowledgename">
          <div class="uploadbox">
            <t-upload
              ref="uploadRef2"
              v-model="files2"
              :multiple="multiple"
              :disabled="disabled"
              :auto-upload="autoUpload"
              :upload-all-files-in-one-request="uploadInOneRequest"
              :is-batch-upload="isBatchUpload"
              :trigger-button-props="{ theme: 'primary', variant: 'base' }"
              placeholder="这是一段没有文件时的占位文本"
              action="//service-bv448zsw-1257786608.gz.apigw.tencentcs.com/api/upload-demo"
              :style="{ marginLeft: '40px' }"
              @fail="handleFail"
              @progress="handleProgress"
            />
            <div>
              <dk-button type="outline">
                <icon-svg
                  style="width: 14px; height: 14px"
                  name="icon-download"
                ></icon-svg>
                下载模版
              </dk-button>
            </div>
          </div>
        </t-form-item>

        <t-form-item label="重复问题处理" name="reserveSelectedRowOnPaginate">
          <div>
            <t-radio-group v-model="formData.Startup">
              <t-radio value="0">覆盖</t-radio>
              <t-radio value="1">部分覆盖</t-radio>
              <t-radio value="2">跳过</t-radio>
            </t-radio-group>
            <div v-show="formData.Startup == '0'">
              导入的知识点将覆盖原有同名知识点，以导入文件中的内容为准，覆盖系统内重复知识点的相关内容
            </div>
            <div v-show="formData.Startup == '2'">
              重复问题不进行处理，保留系统内原知识点相关内容
            </div>
          </div>
        </t-form-item>

        <t-form-item label="" name="questionmethods" label-width="0">
          <div>
            <div>注意事项：</div>
            <div>
              1.上传文件需要符合模版要求，格式为.xlsx扩展名且不删除首行⌈批量导入必读⌋，否则导入将失败
            </div>
          </div>
        </t-form-item>

        <t-form-item class="buttonbut">
          <t-space size="small">
            <t-button theme="default" variant="base" type="reset"
              >取消</t-button
            >
            <t-button theme="primary" type="submit">确定</t-button>
          </t-space>
        </t-form-item>
      </t-form>
    </t-dialog>
  </div>
</template>
    
    <script setup>
import { ref, defineProps, reactive } from "vue";
import { nanoid } from "nanoid";
import { MessagePlugin } from "tdesign-vue-next";
import { getcreatetask } from "@/api/callOutTasks/index.js";
import { afteransweroption } from "../formcolumn/knowledgeBase";

const props = defineProps({
  // 默认选中的部门id
  isshow: {
    type: String,
    default: "",
  },
});
const emit = defineEmits(["event"]);

const formData = reactive({
  Startup: "0", // 重复问题处理
  knowledgename: "", // 知识点
});

const form = ref(null);
//   校验
// const FORM_RULES = {
//   //   templatename: [{ required: true, message: "请输入模版名称" }],
//   //   Industrymsg: [{ required: true, message: "请选择行业信息" }],
//   //   Scenemsg: [{ required: true, message: "请选择场景信息" }],
// };

//取消
const onReset = () => {
  // MessagePlugin.success("重置成功");
  // console.log(form.value);
  formData.Startup = "0";
  form.value.reset();
  emit("event", false);
};
//提交
const onSubmit = async ({ validateResult, firstError }) => {
  if (validateResult === true) {
    MessagePlugin.success("提交成功");
    // emit('event', false);
    console.log(formData);
    // const res = await getcreatetask(formData);
    // console.log(res);
  } else {
    console.log("Validate Errors: ", firstError, validateResult);
    MessagePlugin.warning(firstError);
  }
};

// // 禁用 Input 组件，按下 Enter 键时，触发 submit 事件
// const onEnter = (_, { e }) => {
//   e.preventDefault();
// };
</script>
    
    <style lang="scss" scoped>
.buttonbut {
  display: flex;
  justify-content: space-between;
}

.uploadbox {
  display: flex;
}
:deep(.t-dialog__ctx .t-dialog) {
  max-height: 90%;
  overflow-y: scroll;
}
</style>
    